package com.greendao.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.yizisu.music.and.roomdblibrary.bean.SongWithAlbum;
import com.yizisu.music.and.roomdblibrary.bean.SongWithSinger;

import com.yizisu.music.and.roomdblibrary.bean.SongInfoTable;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "song_info".
*/
public class SongInfoTableDao extends AbstractDao<SongInfoTable, Long> {

    public static final String TABLENAME = "song_info";

    /**
     * Properties of entity SongInfoTable.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property DbId = new Property(0, Long.class, "dbId", true, "_id");
        public final static Property Id = new Property(1, String.class, "id", false, "ID");
        public final static Property Source = new Property(2, Integer.class, "source", false, "SOURCE");
        public final static Property Type = new Property(3, Integer.class, "type", false, "TYPE");
        public final static Property Des = new Property(4, String.class, "des", false, "DES");
        public final static Property Name = new Property(5, String.class, "name", false, "NAME");
        public final static Property CreateTime = new Property(6, Long.class, "createTime", false, "CREATE_TIME");
        public final static Property UpdateTime = new Property(7, Long.class, "updateTime", false, "UPDATE_TIME");
        public final static Property Duration = new Property(8, Long.class, "duration", false, "DURATION");
        public final static Property Size = new Property(9, Long.class, "size", false, "SIZE");
        public final static Property CoverFilePath = new Property(10, String.class, "coverFilePath", false, "COVER_FILE_PATH");
        public final static Property CoverUrlPath = new Property(11, String.class, "coverUrlPath", false, "COVER_URL_PATH");
        public final static Property PlayFilePath = new Property(12, String.class, "playFilePath", false, "PLAY_FILE_PATH");
        public final static Property PlayUrlPath = new Property(13, String.class, "playUrlPath", false, "PLAY_URL_PATH");
        public final static Property LrcFilePath = new Property(14, String.class, "lrcFilePath", false, "LRC_FILE_PATH");
        public final static Property LrcUrlPath = new Property(15, String.class, "lrcUrlPath", false, "LRC_URL_PATH");
        public final static Property LrcString = new Property(16, String.class, "lrcString", false, "LRC_STRING");
    }

    private DaoSession daoSession;

    private Query<SongInfoTable> albumInfoTable_SongInfoTablesQuery;
    private Query<SongInfoTable> singerInfoTable_SongInfoTablesQuery;

    public SongInfoTableDao(DaoConfig config) {
        super(config);
    }
    
    public SongInfoTableDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"song_info\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: dbId
                "\"ID\" TEXT," + // 1: id
                "\"SOURCE\" INTEGER," + // 2: source
                "\"TYPE\" INTEGER," + // 3: type
                "\"DES\" TEXT," + // 4: des
                "\"NAME\" TEXT," + // 5: name
                "\"CREATE_TIME\" INTEGER," + // 6: createTime
                "\"UPDATE_TIME\" INTEGER," + // 7: updateTime
                "\"DURATION\" INTEGER," + // 8: duration
                "\"SIZE\" INTEGER," + // 9: size
                "\"COVER_FILE_PATH\" TEXT," + // 10: coverFilePath
                "\"COVER_URL_PATH\" TEXT," + // 11: coverUrlPath
                "\"PLAY_FILE_PATH\" TEXT," + // 12: playFilePath
                "\"PLAY_URL_PATH\" TEXT," + // 13: playUrlPath
                "\"LRC_FILE_PATH\" TEXT," + // 14: lrcFilePath
                "\"LRC_URL_PATH\" TEXT," + // 15: lrcUrlPath
                "\"LRC_STRING\" TEXT);"); // 16: lrcString
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_song_info_ID ON \"song_info\"" +
                " (\"ID\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"song_info\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, SongInfoTable entity) {
        stmt.clearBindings();
 
        Long dbId = entity.getDbId();
        if (dbId != null) {
            stmt.bindLong(1, dbId);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(2, id);
        }
 
        Integer source = entity.getSource();
        if (source != null) {
            stmt.bindLong(3, source);
        }
 
        Integer type = entity.getType();
        if (type != null) {
            stmt.bindLong(4, type);
        }
 
        String des = entity.getDes();
        if (des != null) {
            stmt.bindString(5, des);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(6, name);
        }
 
        Long createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(7, createTime);
        }
 
        Long updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindLong(8, updateTime);
        }
 
        Long duration = entity.getDuration();
        if (duration != null) {
            stmt.bindLong(9, duration);
        }
 
        Long size = entity.getSize();
        if (size != null) {
            stmt.bindLong(10, size);
        }
 
        String coverFilePath = entity.getCoverFilePath();
        if (coverFilePath != null) {
            stmt.bindString(11, coverFilePath);
        }
 
        String coverUrlPath = entity.getCoverUrlPath();
        if (coverUrlPath != null) {
            stmt.bindString(12, coverUrlPath);
        }
 
        String playFilePath = entity.getPlayFilePath();
        if (playFilePath != null) {
            stmt.bindString(13, playFilePath);
        }
 
        String playUrlPath = entity.getPlayUrlPath();
        if (playUrlPath != null) {
            stmt.bindString(14, playUrlPath);
        }
 
        String lrcFilePath = entity.getLrcFilePath();
        if (lrcFilePath != null) {
            stmt.bindString(15, lrcFilePath);
        }
 
        String lrcUrlPath = entity.getLrcUrlPath();
        if (lrcUrlPath != null) {
            stmt.bindString(16, lrcUrlPath);
        }
 
        String lrcString = entity.getLrcString();
        if (lrcString != null) {
            stmt.bindString(17, lrcString);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SongInfoTable entity) {
        stmt.clearBindings();
 
        Long dbId = entity.getDbId();
        if (dbId != null) {
            stmt.bindLong(1, dbId);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(2, id);
        }
 
        Integer source = entity.getSource();
        if (source != null) {
            stmt.bindLong(3, source);
        }
 
        Integer type = entity.getType();
        if (type != null) {
            stmt.bindLong(4, type);
        }
 
        String des = entity.getDes();
        if (des != null) {
            stmt.bindString(5, des);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(6, name);
        }
 
        Long createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(7, createTime);
        }
 
        Long updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindLong(8, updateTime);
        }
 
        Long duration = entity.getDuration();
        if (duration != null) {
            stmt.bindLong(9, duration);
        }
 
        Long size = entity.getSize();
        if (size != null) {
            stmt.bindLong(10, size);
        }
 
        String coverFilePath = entity.getCoverFilePath();
        if (coverFilePath != null) {
            stmt.bindString(11, coverFilePath);
        }
 
        String coverUrlPath = entity.getCoverUrlPath();
        if (coverUrlPath != null) {
            stmt.bindString(12, coverUrlPath);
        }
 
        String playFilePath = entity.getPlayFilePath();
        if (playFilePath != null) {
            stmt.bindString(13, playFilePath);
        }
 
        String playUrlPath = entity.getPlayUrlPath();
        if (playUrlPath != null) {
            stmt.bindString(14, playUrlPath);
        }
 
        String lrcFilePath = entity.getLrcFilePath();
        if (lrcFilePath != null) {
            stmt.bindString(15, lrcFilePath);
        }
 
        String lrcUrlPath = entity.getLrcUrlPath();
        if (lrcUrlPath != null) {
            stmt.bindString(16, lrcUrlPath);
        }
 
        String lrcString = entity.getLrcString();
        if (lrcString != null) {
            stmt.bindString(17, lrcString);
        }
    }

    @Override
    protected final void attachEntity(SongInfoTable entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public SongInfoTable readEntity(Cursor cursor, int offset) {
        SongInfoTable entity = new SongInfoTable( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // dbId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // id
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // source
            cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // type
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // des
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // name
            cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6), // createTime
            cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7), // updateTime
            cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8), // duration
            cursor.isNull(offset + 9) ? null : cursor.getLong(offset + 9), // size
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // coverFilePath
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // coverUrlPath
            cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // playFilePath
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // playUrlPath
            cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // lrcFilePath
            cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // lrcUrlPath
            cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16) // lrcString
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SongInfoTable entity, int offset) {
        entity.setDbId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setSource(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setType(cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3));
        entity.setDes(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setName(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setCreateTime(cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6));
        entity.setUpdateTime(cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7));
        entity.setDuration(cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8));
        entity.setSize(cursor.isNull(offset + 9) ? null : cursor.getLong(offset + 9));
        entity.setCoverFilePath(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setCoverUrlPath(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setPlayFilePath(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
        entity.setPlayUrlPath(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
        entity.setLrcFilePath(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
        entity.setLrcUrlPath(cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15));
        entity.setLrcString(cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(SongInfoTable entity, long rowId) {
        entity.setDbId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(SongInfoTable entity) {
        if(entity != null) {
            return entity.getDbId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(SongInfoTable entity) {
        return entity.getDbId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "songInfoTables" to-many relationship of AlbumInfoTable. */
    public List<SongInfoTable> _queryAlbumInfoTable_SongInfoTables(Long albumId) {
        synchronized (this) {
            if (albumInfoTable_SongInfoTablesQuery == null) {
                QueryBuilder<SongInfoTable> queryBuilder = queryBuilder();
                queryBuilder.join(SongWithAlbum.class, SongWithAlbumDao.Properties.SongId)
                    .where(SongWithAlbumDao.Properties.AlbumId.eq(albumId));
                albumInfoTable_SongInfoTablesQuery = queryBuilder.build();
            }
        }
        Query<SongInfoTable> query = albumInfoTable_SongInfoTablesQuery.forCurrentThread();
        query.setParameter(0, albumId);
        return query.list();
    }

    /** Internal query to resolve the "songInfoTables" to-many relationship of SingerInfoTable. */
    public List<SongInfoTable> _querySingerInfoTable_SongInfoTables(Long singerId) {
        synchronized (this) {
            if (singerInfoTable_SongInfoTablesQuery == null) {
                QueryBuilder<SongInfoTable> queryBuilder = queryBuilder();
                queryBuilder.join(SongWithSinger.class, SongWithSingerDao.Properties.SongId)
                    .where(SongWithSingerDao.Properties.SingerId.eq(singerId));
                singerInfoTable_SongInfoTablesQuery = queryBuilder.build();
            }
        }
        Query<SongInfoTable> query = singerInfoTable_SongInfoTablesQuery.forCurrentThread();
        query.setParameter(0, singerId);
        return query.list();
    }

}
